﻿

using System.Diagnostics;
using System.Net;
using System.Net.Sockets.Kcp.Simple;



static async void Send(SimpleKcpClient client, string v)
{
    var buffer = System.Text.Encoding.UTF8.GetBytes(v);
    client.SendAsync(buffer, buffer.Length);
    var resp = await client.ReceiveAsync();
    var respstr = System.Text.Encoding.UTF8.GetString(resp);
    Console.WriteLine($"收到服务器回复:    {respstr}");
}


Console.WriteLine("Press F1 send word.......");

IPEndPoint end = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, 40001);

SimpleKcpClient kcpClient = new SimpleKcpClient(50001, end);
kcpClient.kcp.TraceListener = new ConsoleTraceListener();
Task.Run(async () =>
{
    while (true)
    {
        kcpClient.kcp.Update(DateTimeOffset.UtcNow);
        await Task.Delay(10);
    }
});

while (true)
{
    var k = Console.ReadKey();
    if (k.Key == ConsoleKey.S)
    {
        Send(kcpClient, "发送一条消息");
    }
}

Console.ReadLine();